import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
// import { join as pathJoin } from 'path'
export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1598536404340_5694';

  // add your egg config in here
  config.security = {
    csrf: {
      enable: false,
      ignoreJSON: true,
    },
    // 白名单
    // domainWhiteList: ['http://localhost:8080'],
  };
  config.cluster = {
    listen: {
      path: '',
      port: 6464,
      hostname: '0.0.0.0'
    }
  }
  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };
  config.middleware = ['csrfToken'];

  //#region 
  /* config.sequelize = {
    dialect: 'mysql',
    host: 'localhost',
    username: 'root',
    password: 'root',
    port: 3306,
    database: 'qaplan_kino',
  }; */
  // config.mysql = {
  //   // 单数据库信息配置
  //   client: {
  //     // host
  //     host: 'localhost',
  //     // 端口号
  //     port: '3306',
  //     // 用户名
  //     user: 'root',
  //     // 密码
  //     password: 'root',
  //     // 数据库名
  //     database: 'qaplan_kino',
  //   },
  //   // 是否加载到 app 上，默认开启
  //   app: true,
  //   // 是否加载到 agent 上，默认关闭
  //   agent: false,
  // };
  /* config.validateJoi = {
    abortEarly: false,
  }; */
  /* config.static = {
    prefix: '/public/',
    dir: [pathJoin(appInfo.baseDir, 'app/public')]
  } */
  //#endregion
  config.cors = {
    origin: ctx => ctx.get('origin'),
    credentials: true,  //允许Cookie可以跨域
    allowMethods: 'GET,POST,OPTIONS'
  };
  config.joi = {
    options: {},
    locale: {
      'zh-cn': {},
    },
    throw: false, // throw immediately when capture exception
    // throwHandle: (error) => { return error; }, // error message format when throw is true
    errorHandle: error => { return error }, // error message format when throw is false
    resultHandle: result => { return result; } // fromat result
  };
  /* exports.alinode = {
    // 从 `Node.js 性能平台` 获取对应的接入参数
    appid: '88820',
    secret: 'ff1aa39d39b470574a17d5d77743d9b6b957a661',
  }; */
  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
